package com.zzyl.nursing.service.impl;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zzyl.nursing.domain.Reservation;
import com.zzyl.nursing.mapper.ReservationMapper;
import com.zzyl.nursing.service.IReservationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.function.Function;
@Service
public class ReservationServiceImpl extends ServiceImpl<ReservationMapper,Reservation> implements IReservationService {
    @Autowired
    private ReservationMapper reservationMapper;

    /**
     * 分页查询预约信息
     *
     * @param reservation
     * @return
     */
    @Override
    public List<Reservation> selectReservationPage(Reservation reservation) {
        return  reservationMapper.selectReservationPage(reservation);
    }
    /**
     * 新增预约信息
     *
     * @param reservation 预约信息
     * @return 结果
     */
    @Override
    public int insertReservation(Reservation reservation)
    {
        return save(reservation) ? 1 : 0;
    }
    /**
     * 查询取消预约数量
     *
     * @return 数量
     */
    @Override
    public Long selectReservationCount() {
        Long count = reservationMapper.selectCount(Wrappers.<Reservation>lambdaQuery().eq(Reservation::getStatus, 2));
        return count;
    }
    /**
     * 取消预约
     *
     * @param id 预约ID
     * @return 结果
     */
    @Override
    public void updateReservationStatus(Long id) {
        //查询取消次数
        Long count = count(Wrappers.<Reservation>lambdaQuery().eq(Reservation::getId, id));
        reservationMapper.updateReservationStatus(id);
        if (count > 3) {
            System.out.println("该账号今日已不可进行预约,是否还要继续?");
        }
        //记录取消次数
        count+= 1;
    }

    @Override
    public boolean saveBatch(Collection<Reservation> entityList, int batchSize) {
        return false;
    }

    @Override
    public boolean saveOrUpdateBatch(Collection<Reservation> entityList, int batchSize) {
        return false;
    }

    @Override
    public boolean updateBatchById(Collection<Reservation> entityList, int batchSize) {
        return false;
    }

    @Override
    public boolean saveOrUpdate(Reservation entity) {
        return false;
    }

    @Override
    public Reservation getOne(Wrapper<Reservation> queryWrapper, boolean throwEx) {
        return null;
    }

    @Override
    public Map<String, Object> getMap(Wrapper<Reservation> queryWrapper) {
        return null;
    }

    @Override
    public <V> V getObj(Wrapper<Reservation> queryWrapper, Function<? super Object, V> mapper) {
        return null;
    }

    @Override
    public ReservationMapper getBaseMapper() {
        return null;
    }

    @Override
    public Class<Reservation> getEntityClass() {
        return null;
    }
}
